package com.ztools.wx.controller;

import com.ztools.common.model.pc.coupon.CouponRecord;
import com.ztools.common.util.common.Result;
import com.ztools.wx.service.WxCouponService;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: seeTools
 * @Date: 2023/5/14  11:51
 * @Version 1.0
 */
@RestController
@RequestMapping("/wx/coupon")
public class WxCouponController {

    @Resource
    private WxCouponService wxCouponService;

    @RequestMapping("/info")
    public Result getCouponInfo(@RequestBody CouponRecord couponRecord) {
        List<CouponRecord> couponRecords = wxCouponService.findByObject(couponRecord);
        if (couponRecords.size() > 0) {
            return Result.success("获取成功").data(couponRecords);
        }
        return Result.error();
    }

    @RequestMapping("/info/{memberId}")
    public Result getCouponInfo(@PathVariable Long memberId) {
        List<CouponRecord> couponRecords = wxCouponService.getCouponInfo(memberId);
        if (couponRecords.size() > 0) {
            return Result.success("获取成功").data(couponRecords);
        }
        return Result.error();
    }

    @RequestMapping("/type/number/{memberId}")
    public Result getCouponTypeNumber(@PathVariable Long memberId) {
        List<CouponRecord> couponTypeNumber = wxCouponService.getCouponTypeNumber(memberId);
        if (couponTypeNumber.size() > 0) {
            return Result.success("获取成功").data(couponTypeNumber);
        }
        return Result.error();
    }

    @RequestMapping("/packet")
    public Result getCouponPacket(@RequestBody CouponRecord couponRecord) {
        CouponRecord couponPacket = wxCouponService.getCouponPacket(couponRecord);
        if (couponPacket != null) {
            return Result.success("获取成功").data(couponPacket);
        }
        return Result.error();
    }

    @RequestMapping("/usable")
    public Result getCouponUsable(@RequestBody CouponRecord couponRecord) {
        CouponRecord couponPacket = wxCouponService.getCouponUsable(couponRecord);
        if (couponPacket != null) {
            return Result.success("获取成功").data(couponPacket);
        }
        return Result.error();
    }
}
